package com.huwei.data.manager;

import java.util.Objects;

public class DataSourceUtil {

	private DataSourceManagerFacotry dsmf;
	
	public DataSourceUtil() {}
	
	public DataSourceUtil(DataSourceManagerFacotry dsmf) {
		this.dsmf = dsmf;
	}

	public<T> DataSourceOperation next(Class<T> superClass ,Class<? extends T> cls) {
		DataSourceManager<T> dsm = dsmf == null ? null : dsmf.getDataManager(superClass);
		return dsm == null ? null : dsm.next(cls);
	}
	
	public<T> Object invokeMethodByNextDataSource(Class<T> superClass ,Class<? extends T> cls) {
		DataSourceOperation dso = next(superClass, cls);
		if(Objects.nonNull(dso)) {
			return dso.invokeCurrentMethod();
		}
		return null;
	}
}
